var app = getApp()
var util = require('../../utils/util.js')
var md5 = require('../md5.js');
Page({
  data: {
    currentTab: 0,
    showModal: false,
    luzsshow: false,
    "bnrUrl": [{
      "url": "../../images/2.jpg"
    }, {
      "url": "../../images/2.jpg"
    }, {
      "url": "../../images/2.jpg"
    }],
    "productOne": [{
      "url": "../../images/2.jpg"
    }, {
      "url": "../../images/3.jpg"
    }, {
      "url": "../../images/2.jpg"
    }],
    "productTwo": [{
      "url": "../../images/3.jpg"
    }, {
      "url": "../../images/2.jpg"
    }, {
      "url": "../../images/2.jpg"
    }],
  },
  submit: function (e) {
    var idandurl = e.currentTarget.dataset.zlid
    var delzlid = (idandurl.split('-'))[0]
    var fxurl = (idandurl.split('-'))[1]
    this.setData({
      delzlid: delzlid,
      fxurl: fxurl,
      showModal: true
    })
  },
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh({
      complete: (res) => { },
    });
  },
  //底部导航跳转
  toAiIndex: function () {
    util.toAiIndex()
  },
  toContactsIng: function () {
    util.toContactsIng()
  },
  toProductRevision: function () {
    util.toProductRevision()
  },
  toBadge: function () {
    util.toBadge()
  },
  toMy: function () {
    util.toMy()
  },
  toChangeShow: function () {
    var that = this
    that.setData({
      luzsshow: false
    })
  },
  onShareAppMessage: function (res) {
    var that = this
    that.setData({
      showModal: false
    })
    var fxurl = 'pages/receiveInfo/receiveInfolj?urlmesg=' +that.data.fxurl
    console.log('fxurl=' + fxurl)
    if (res.from === 'button') { }
    return {
      title: '资料分享',
      path: fxurl,
      success: function (res) { }
    }
  },
  preventTouchMove: function () {

  },


  go: function (e) {
    var that = this;
    //获取关键词
    var keyword = e.detail.value
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=' + exhibitionid)
    console.log('u=' + u)
    if ((wx.getStorageSync('exhibitionid') || !"".trim() == wx.getStorageSync('exhibitionid'))
      && (wx.getStorageSync('u') || !"".trim() == wx.getStorageSync('u'))) {
      //默认最新（调用pico接口）
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var url = app.globalData.picoaddress + '/attendee/materials/list'
      var k = {}
      var sign=''
      k["v"] = '1.0.0'
      k["client"] = 'ios'
      k["timestamp"] = timestamp
      k["lan"] = 'cn'
      k["exhibitionid"] = exhibitionid
      k["sorttype"] = 1
      k["u"] = u
      k["keyword"] = keyword
      if (keyword || !"".trim() == keyword) {
        k["keyword"] = keyword
        sign = sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'keyword' + keyword + 'sorttype1' + 'timestamp' + timestamp + app.globalData.picotoken
      }else{
        sign = sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'sorttype1' + 'timestamp' + timestamp + app.globalData.picotoken
      }
      console.log(sign)
      var curb64 = md5.zhMD5(sign)
      console.log(curb64)
      k["sign"] = curb64
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: url,
        method: 'post',
        data: k,
        success(res) {
          console.log(res)
          var mesg = res.data
          console.log('mesg=' + mesg)
          var curdata = mesg.data
          that.setData({
            curzlMesg: curdata
          });
        }, fail: res => {
          console.log(res, "error")
        }

      })
    } else {
      wx.redirectTo({
        url: '../signInbyPhone/signIn'
      })
    }
  },
  //查看资料跳转receiveInfolj
  toReceiveInfolj(e) {
    console.log(e)
    var urlmesg = e.currentTarget.dataset.urlmesg
    wx.navigateTo({
      url: '../receiveInfo/receiveInfolj?urlmesg=' + urlmesg,
    })
  },
  onLoad: function (options) {
    var that = this;
    // 页面初始化 options为页面跳转所带来的参数 
    //获取缓存展会id和用户id存在则获取最新联系人列表
    //设置语言0:中文，1：英文
    var setlanguage = wx.getStorageSync('setlanguage')
    if ((wx.getStorageSync('setlanguage') || !"".trim() == wx.getStorageSync('setlanguage'))) {
      this.setData({
        setlanguage: wx.getStorageSync('setlanguage')
      })
      if (setlanguage == 1) {
        wx.setNavigationBarTitle({
          title: 'Material'
        })
      } else {
        wx.setNavigationBarTitle({
          title: '资料'
        })
      }
    } else {
      wx.setStorageSync('setlanguage', 0);
      this.setData({
        setlanguage: 0
      })
    }
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=' + exhibitionid)
    console.log('u=' + u)
    if ((wx.getStorageSync('exhibitionid') || !"".trim() == wx.getStorageSync('exhibitionid'))
      && (wx.getStorageSync('u') || !"".trim() == wx.getStorageSync('u'))) {
      //默认最新（调用pico接口）
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var url = app.globalData.picoaddress + '/attendee/materials/list'
      var k = {}
      k["v"] = '1.0.0'
      k["client"] = 'ios'
      k["timestamp"] = timestamp
      k["lan"] = 'cn'
      k["exhibitionid"] = exhibitionid
      k["sorttype"] = 1
      k["u"] = u

      var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid +'sorttype1' + 'timestamp' + timestamp + app.globalData.picotoken
      console.log(sign)
      var curb64 = md5.hexMD5(sign)
      console.log(curb64)
      k["sign"] = curb64
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: url,
        method: 'post',
        data: k,
        success(res) {
          console.log(res)
          var mesg = res.data
          console.log('mesg=' + mesg)
          var curdata = mesg.data
          that.setData({
            curzlMesg: curdata
          });
        }, fail: res => {
          console.log(res, "error")
        }

      })
    } else {
      wx.redirectTo({
        url: '../signInbyPhone/signIn'
      })
    }


  },
  sczl:function(e) {
    console.log(e)
    var materialid = e.currentTarget.dataset.zlid
    var that = this
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=' + exhibitionid)
    console.log('u=' + u)
    if (!(exhibitionid=='0' && u=='0')) {
      //默认最新（调用pico接口）
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var url = app.globalData.picoaddress + '/attendee/materials/collect'
      var k = {}
      k["v"] = '1.0.0'
      k["client"] = 'ios'
      k["timestamp"] = timestamp
      k["lan"] = 'cn'
      k["exhibitionid"] = exhibitionid
      k["materialid"] = materialid
      k["u"] = u
      var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'materialid' + materialid + 'timestamp' + timestamp + app.globalData.picotoken
      console.log(sign)
      var curb64 = md5.hexMD5(sign)
      console.log(curb64)
      k["sign"] = curb64
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: url,
        method: 'post',
        data: k,
        success(res) {
         console.log(res)
          if ((wx.getStorageSync('exhibitionid') || !"".trim() == wx.getStorageSync('exhibitionid'))
            && (wx.getStorageSync('u') || !"".trim() == wx.getStorageSync('u'))) {
            //默认最新（调用pico接口）
            var timestamp = Date.parse(new Date());
            timestamp = timestamp / 1000;
            var url = app.globalData.picoaddress + '/attendee/materials/list'
            var k = {}
            k["v"] = '1.0.0'
            k["client"] = 'ios'
            k["timestamp"] = timestamp
            k["lan"] = 'cn'
            k["exhibitionid"] = exhibitionid
            k["sorttype"] = 1
            k["u"] = u

            var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'sorttype1' + 'timestamp' + timestamp + app.globalData.picotoken
            console.log(sign)
            var curb64 = md5.hexMD5(sign)
            console.log(curb64)
            k["sign"] = curb64
            wx.request({
              header: {
                'content-type': 'application/x-www-form-urlencoded',
              },
              url: url,
              method: 'post',
              data: k,
              success(res) {
                console.log(res)
                var mesg = res.data
                console.log('mesg=' + mesg)
                var curdata = mesg.data
                that.setData({
                  curzlMesg: curdata
                });
              }, fail: res => {
                console.log(res, "error")
              }

            })
          }
        }, fail: res => {
          console.log(res, "error")
        }

      })

    } else {
      wx.navigateTo({
        url: '../signInbyPhone/signIn'
      })
    }
  },
  catchme: function (e) {  
    var that = this
    var materialidandtoid = e.currentTarget.dataset.zlid
    var toid = (materialidandtoid.split('-'))[0]
    var materialid = (materialidandtoid.split('-'))[1]
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=' + exhibitionid)
    console.log('u=' + u)
    if (!(exhibitionid=='0' && u=='0')) {
      //默认最新（调用pico接口）
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var url = app.globalData.picoaddress + '/attendee/exhibitors/contactme'
      var k = {}
      k["v"] = '1.0.0'
      k["client"] = 'ios'
      k["timestamp"] = timestamp
      k["lan"] = 'cn'
      k["exhibitionid"] = exhibitionid
      k["materialid"] = materialid
      k["toid"] = toid
      k["u"] = u
      var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'materialid' + materialid + 'timestamp' + timestamp + 'toid' + toid + app.globalData.picotoken
      console.log(sign)
      var curb64 = md5.hexMD5(sign)
      console.log(curb64)
      k["sign"] = curb64
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: url,
        method: 'post',
        data: k,
        success(res) {
          console.log(res)
          var mesg = res.data
          console.log('mesg=' + mesg)
          if (mesg.code == 200) {
            that.setData({
              luzsshow: true
            })
          } else {
            wx.showToast({
              title: mesg.message,
              icon: 'none',
              duration: 1500
            })
          }
        }, fail: res => {
          console.log(res, "error")
        }

      })

    } else {
      wx.navigateTo({
        url: '../signInbyPhone/signIn'
      })
    }
  },
  catchmp: function (e) {
    var that = this
    var zsidandtoid = e.currentTarget.dataset.zsid
    var toid = (zsidandtoid.split('-'))[0]
    var exhibitorid = (zsidandtoid.split('-'))[1]
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=' + exhibitionid)
    console.log('u=' + u)
    if (!(exhibitionid=='0' && u=='0')) {
      //默认最新（调用pico接口）
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var url = app.globalData.picoaddress + '/attendee/exhibitors/getexhibitorcard'
      var k = {}
      k["v"] = '1.0.0'
      k["client"] = 'ios'
      k["timestamp"] = timestamp
      k["lan"] = 'cn'
      k["exhibitionid"] = exhibitionid
      k["exhibitorid"] = exhibitorid
      k["u"] = u
      var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'exhibitorid' + exhibitorid + 'timestamp' + timestamp + app.globalData.picotoken
      console.log(sign)
      var curb64 = md5.hexMD5(sign)
      console.log(curb64)
      k["sign"] = curb64
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: url,
        method: 'post',
        data: k,
        success(res) {
          console.log(res)
          console.log('mesg=' + mesg)
          var mesg = res.data
          console.log('mesg=' + mesg)
          if (mesg.code == 200) {
            wx.showToast({
              title: '展商名片成功添加到通讯录',
              icon: 'none',
              duration: 1500
            })
            wx.navigateTo({
              url: '../pageDetail/pageDetails?attendeeid=' + toid,
            })

          } else {
            wx.showToast({
              title: mesg.message,
              icon: 'none',
              duration: 1500
            })
          }
        }, fail: res => {
          console.log(res, "error")
        }

      })

    } else {
      wx.navigateTo({
        url: '../signInbyPhone/signIn'
      })
    }
  },
  delzl: function () {
    var that = this
    var materialid = that.data.delzlid
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=' + exhibitionid)
    console.log('u=' + u)
    if ((wx.getStorageSync('exhibitionid') || !"".trim() == wx.getStorageSync('exhibitionid'))
      && (wx.getStorageSync('u') || !"".trim() == wx.getStorageSync('u'))) {
      //默认最新（调用pico接口）
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var url = app.globalData.picoaddress + '/attendee/materials/del'
      var k = {}
      k["v"] = '1.0.0'
      k["client"] = 'ios'
      k["timestamp"] = timestamp
      k["lan"] = 'cn'
      k["exhibitionid"] = exhibitionid
      k["materialid"] = materialid
      k["u"] = u
      var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'materialid' + materialid + 'timestamp' + timestamp + app.globalData.picotoken
      console.log(sign)
      var curb64 = md5.hexMD5(sign)
      console.log(curb64)
      k["sign"] = curb64
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: url,
        method: 'post',
        data: k,
        success(res) {
          console.log(res)
          if ((wx.getStorageSync('exhibitionid') || !"".trim() == wx.getStorageSync('exhibitionid'))
            && (wx.getStorageSync('u') || !"".trim() == wx.getStorageSync('u'))) {
            //默认最新（调用pico接口）
            var timestamp = Date.parse(new Date());
            timestamp = timestamp / 1000;
            var url = app.globalData.picoaddress + '/attendee/materials/list'
            var k = {}
            k["v"] = '1.0.0'
            k["client"] = 'ios'
            k["timestamp"] = timestamp
            k["lan"] = 'cn'
            k["exhibitionid"] = exhibitionid
            k["sorttype"] = 1
            k["u"] = u

            var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'sorttype1' + 'timestamp' + timestamp + app.globalData.picotoken
            console.log(sign)
            var curb64 = md5.hexMD5(sign)
            console.log(curb64)
            k["sign"] = curb64
            wx.request({
              header: {
                'content-type': 'application/x-www-form-urlencoded',
              },
              url: url,
              method: 'post',
              data: k,
              success(res) {
                console.log(res)
                var mesg = res.data
                console.log('mesg=' + mesg)
                var curdata = mesg.data
                that.setData({
                  curzlMesg: curdata,
                  showModal: false
                });
               
              }, fail: res => {
                console.log(res, "error")
              }

            })
          }
        }, fail: res => {
          console.log(res, "error")
        }

      })

    } else {
      wx.redirectTo({
        url: '../signInbyPhone/signIn'
      })
    }
  },
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  del: function (e) {
    var that = this;
    this.setData({
      showModal: false
    })
  },
  //点击切换
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  }
})